function createCompareFunction(argsName){
  return function(obj1,obj2){
    let value1 = obj1[argsName];
    let value2 = obj2[argsName];
    if(value1 < value2) return -1;
    if(value1 = value2) return  0;
    if(value1 > value2) return  1;
  }
}
let person=[ 
  {name:'alice',age:12},
  {name:'smith',age:11},
  {name:'tom',age:15}
]
console.log(person);
person.sort(createCompareFunction('age'));
console.log(person);

// [
//   { name: 'alice', age: 12 },
//   { name: 'smith', age: 11 },
//   { name: 'tom', age: 15 }
// ]
// [
//   { name: 'smith', age: 11 },
//   { name: 'alice', age: 12 },
//   { name: 'tom', age: 15 }
// ]